import { useModel } from "umi";
import { useReactive } from "ahooks";
import { useEffect } from "react";

const useOffShelf = () => {
    const { remoteData } = useModel("global");
    const { organizationUuid } = useModel("organization.info");

    const state = useReactive({
        loading: false,
        applications: [],
    });

    const loadOffShelfApplications = async () => {
        state.loading = true;
        let res = await remoteData({
            object: "bnt-application-operation-center-service",
            serviceName: "/developer/person/application/getAll",
            params: {
                appSdud: organizationUuid,
                appStat: "已下架",
            },
        });
        state.applications = res || [];
        state.loading = false;
    };

    useEffect(() => {
        organizationUuid && loadOffShelfApplications();
    }, [organizationUuid]);

    return { ...state, loadOffShelfApplications };
};

export default useOffShelf;
